﻿
using System.Diagnostics;
using Expressions.Compiler;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Expressions.Compiler.Internal;

namespace Tests
{


    /// <summary>
    ///This is a test class for Test4_ and is intended
    ///to contain all Test4_ Unit Tests
    ///</summary>
    [TestClass()]
    public class Test4__
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        private Entity CreateGrammar()
        {
            Terminal[] _ = { '0', '1', '(', ')', '+', '-', '*', '/' };

            Nonterminal G = "G";
            Nonterminal E = "E";
            Nonterminal Eopt = "E'";

            Nonterminal T = "T";
            Nonterminal Topt = "T'";

            Nonterminal F = "F";
            Nonterminal N = "N";

            G.Definition = new Rules
            {
                () => E[false] + Terminal.Null
            };

            E.Definition = new Rules
            {
                () => T[false] + Eopt[true]
            };

            T.Definition = new Rules
            {
                () => F[false] + Topt[true]
            };

            F.Definition = new Rules
            {
                () => N[false],
                () => '(' + E[false] + ')'
            };

            N.Definition = new Rules
            {
                () => '0',
                () => '1'
            };

            Eopt.Definition = new Rules
            {
                () => '+' + E[false],
                () => '-' + E[false]
            };

            Topt.Definition = new Rules
            {
                () => '*' + T[false],
                () => '/' + T[false]
            };


            G.Initialize();
            G.Validate();

            return G;
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_1()
        {
            Entity target = CreateGrammar();
            Parser input = "0";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_2()
        {
            Entity target = CreateGrammar();
            Parser input = "(0-((0*1)/1+1))-(1/1";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_3()
        {
            Entity target = CreateGrammar();
            Parser input = "(0-((0*1)/1+1))-(1/1))";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_4()
        {
            Entity target = CreateGrammar();
            Parser input = "(0-((0*1)/1+1))-(1/1)";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_5()
        {
            Entity target = CreateGrammar();
            Parser input = "";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }


        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_6()
        {
            Entity target = CreateGrammar();
            Parser input = "(0+e)";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_7()
        {
            Entity target = CreateGrammar();
            Parser input = "0";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_8()
        {
            Entity target = CreateGrammar();
            Parser input = "(0-1)-1";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_9()
        {
            Entity target = CreateGrammar();
            Parser input = "0(+e)";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == false;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_10()
        {
            Entity target = CreateGrammar();
            Parser input = "(0-1)+1";
            bool expected = true;
            bool actual;
            actual = target.Parse(input) == true;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_11()
        {
            Entity target = CreateGrammar();
            Parser input = "(0-((0*1)/1+1))-(1/1)";
            target.Parse(input);
            string expected = "(0-((0*1)/1+1))-(1/1)";
            string actual = input.Text;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_12()
        {
            Nonterminal target = "P";
            bool expected = false;
            bool actual = target.Equals((Entity)null);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_13()
        {
            Nonterminal target = "P";
            Nonterminal Q = "P";
            bool expected = true;
            bool actual = target.GetHashCode() == Q.GetHashCode();
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_14()
        {
            Tokens stream = new Tokens { '(' };
            bool expected = true;
            bool actual = stream.GetEnumerator() != null;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_15()
        {
            Nonterminal target = "P";
            bool expected = false;
            bool actual = target.Equals((char)Terminal.Null);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_16()
        {
            Nonterminal target = "P";
            bool expected = false;
            bool actual = target.Equals((string)Terminal.Null.ToString());
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_17()
        {
            Nonterminal target = "P";
            Reference reference = new Reference(target, true);
            bool expected = true;
            bool actual = reference.Name == target.Name;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_18()
        {
            Nonterminal target = "Q";
            bool expected = true;
            bool actual = target.Equals(target);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Parse
        ///</summary>
        [TestMethod(), Conditional("DEBUG")]
        public void Test4_19()
        {
            Nonterminal target1 = "Q";
            Nonterminal target2 = "Q";
            bool expected = true;
            bool actual = target1.Equals((Entity)target2);
            Assert.AreEqual(expected, actual);
        }
    }
}
